package main

import (
	"fmt"
	"time"
)

func main() {
	// Create a new timer that will fire after 5 seconds
	timer := time.NewTimer(5 * time.Second)

	// Create a channel to communicate with the goroutine that will perform the task
	taskChan := make(chan bool)

	// Start a goroutine to perform the task
	go func() {
		// Simulate a task that takes 10 seconds to complete
		time.Sleep(2 * time.Second)
		// Signal that the task has completed
		taskChan <- true
	}()

	// Wait for either the task to complete or for the timer to fire
	select {
	case <-taskChan:
		fmt.Println("Task completed successfully")
	case <-timer.C:
		fmt.Println("Task timed out")
	}

	// Stop the timer
	timer.Stop()
}
